package com.yanqu.road.server.logic.activity.condition.goddess;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.args.ValueParamArgs;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseNewRankActivityCondition;
import com.yanqu.road.utils.string.StringUtils;

import java.math.BigInteger;

public class GoddessMissionRankCondition extends BaseNewRankActivityCondition {

    public GoddessMissionRankCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
        super(activityInfo, activityConditionInfo, baseActivityData);
    }

    @Override
    protected void player_BoardLevelHandle(Object object) {
        ValueParamArgs args = (ValueParamArgs) object;
        BigInteger score = BigInteger.valueOf(args.getValue());
        boolean change = false;
        if (score.compareTo(getValue()) > 0) {
            change = true;
        }
        long old = 0L;
        if(!StringUtils.isNullOrEmpty(getParam())){
            old = Long.parseLong(getParam());
        }
        if(change){
            setParam("0");
        }else {
            long point = Long.parseLong(args.getParam());
            if(point > old) {
                setParam(args.getParam());
                change = true;
            }
        }
        if(change) {
            setValue(score);
            //重新生成排行榜
            rankChange();
        }
    }

    @Override
    public void addTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.GoddessMissionRank.getValue(), handle);
    }

    @Override
    public void removeTrigger(GamePlayer player) {
        player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.GoddessMissionRank.getValue(), handle);
    }
}
